import {fileURLToPath, URL} from 'node:url'
import { ViteImageOptimizer } from 'vite-plugin-image-optimizer';
import {defineConfig, loadEnv} from 'vite'
import legacy from '@vitejs/plugin-legacy'
import vue2 from '@vitejs/plugin-vue2'
import viteCompression from 'vite-plugin-compression'
// https://vitejs.dev/config/

export default defineConfig(({mode}) => { // 获取当前环境的配置
    const config = loadEnv(mode, './')
    return {
        server: {
            proxy: {
                '/basice': {
                    target: config.VITE_URL,
                    changeOrigin: true,
                    rewrite: (path) => path.replace(/^\/basice/, '')
                }
            }
        },
        plugins: [
            vue2(), legacy(
                {targets: ['ie >= 11'], additionalLegacyPolyfills: ['regenerator-runtime/runtime']}
            ),viteCompression(),ViteImageOptimizer
        ],
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url))
            }
        }
    }
})
